package cn.wusifx;

import cn.wusifx.zabbix.Zabbix;
import cn.wusifx.zabbix.request.builder.AuthRequestBuilder;
import cn.wusifx.zabbix.request.builder.UnAuthRequestBuilder;
import cn.wusifx.zabbix.request.builder.alert.AlertGetRequestBuilder;
import cn.wusifx.zabbix.request.builder.user.UserCreateRequestBuilder;
import cn.wusifx.zabbix.request.builder.user.UserGroupCreateRequestBuilder;
import cn.wusifx.zabbix.response.AuthResponse;
import cn.wusifx.zabbix.response.BaseResponse;
import cn.wusifx.zabbix.response.UnAuthResponse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class App {
    public static void main(String[] args) {
        Zabbix zabbix = new Zabbix();
        zabbix.init("https://www.zabbix.com/zabbix");
        BaseResponse<Map> baseResponse = zabbix.call(new AuthRequestBuilder(1L).setUserName("username").setPassword("password").builder());
        System.out.println(baseResponse.getResult());

        BaseResponse<String> authResponse = zabbix.call(new AuthRequestBuilder(1L).setUserName("username").setPassword("password").builder());
        String auth = authResponse.getResult();

        BaseResponse<Map> alertResponse = zabbix.call(new AlertGetRequestBuilder(1L, auth).builder());
        System.out.println(alertResponse.getResult());

        BaseResponse<Boolean> unAuthResponse = zabbix.call(new UnAuthRequestBuilder(1L, auth).builder());
        System.out.println(unAuthResponse.getResult());


        String auth2 = zabbix.auth("username", "password");//login

        BaseResponse<Map<String, List<String>>> userGroupResponse = zabbix.call(new UserGroupCreateRequestBuilder(zabbix.getAuth())//create user group
                .setName("testGroup")
                .builder());
        String userGroupId = userGroupResponse.getResult().get("usrgrpids").get(0);//get user group id
        zabbix.call(new UserCreateRequestBuilder(zabbix.getAuth())//create user and link to group by group id
                .setAlias("alias").setPasswd("p@ssw0rd")
                .setUsrgrps(new ArrayList() {{
                    add(new HashMap() {{
                        put("usrgrpid", userGroupId);
                    }});
                }}).builder());

        zabbix.unAuth(auth2);//zabbix.unAuth();//logout

    }
}
